﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Reflection;
using System.Text;

namespace CMS.Service.EnumHelper
{
    public enum Enum_Wrk_Status : int
    {
        [Display(Name = "Báo giá")]
        Quotation = 1,
        [Display(Name = "Hẹn lại")]
        NextTimes = 2,
        [Display(Name = "Mang về")]
        BringBack = 3,
        [Display(Name = "Hủy bỏ")]
        Cancel = 4,
        [Display(Name = "Hoàn tất")]
        Complete = 5
    }

    public static class EnumHelper
    {
        /// <summary>
        /// Get the display attribute of the enum
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static string DisplayName(this Enum value)
        {
            Type enumType = value.GetType();
            var enumValue = Enum.GetName(enumType, value);
            MemberInfo member = enumType.GetMember(enumValue)[0];

            if (member.IsDefined(typeof(DisplayAttribute), false))
            {
                var attrs = member.GetCustomAttributes(typeof(DisplayAttribute), false);
                var outString = ((DisplayAttribute)attrs[0]).Name;

                if (((DisplayAttribute)attrs[0]).ResourceType != null)
                {
                    outString = ((DisplayAttribute)attrs[0]).GetName();
                }

                return outString;
            }
            else
            {
                return member.Name;
            }
        }

        public static List<KeyValuePair<int, string>> Get_Enum_Wrk_Status()
        {
            List<KeyValuePair<int, string>> rst = new List<KeyValuePair<int, string>>();
            foreach (Enum_Wrk_Status item in (Enum_Wrk_Status[])Enum.GetValues(typeof(Enum_Wrk_Status)))
            {
                rst.Add(new KeyValuePair<int, string>((int)item, item.DisplayName()));
            }
            return rst;
        }
    }
}
